package com.app.stick.device.controller;

import java.util.List;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import javax.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.app.common.annotation.Log;
import com.app.common.core.controller.BaseController;
import com.app.common.core.domain.ApiResult;
import com.app.common.enums.BusinessType;
import com.app.stick.device.domain.BizDeviceInfo;
import com.app.stick.device.service.IBizDeviceInfoService;
import com.app.common.utils.poi.ExcelUtil;

/**
 * 设备信息Controller
 *
 * @author app
 * @date 2023-12-16
 */
@Api(value = "设备信息", tags = {"WEB-设备信息接口"})
@RestController
@RequestMapping("/device/info")
public class BizDeviceInfoController extends BaseController
{
    @Resource
    private IBizDeviceInfoService bizDeviceInfoService;

    /**
     * 查询设备信息列表
     */
    @ApiOperation("查询设备信息列表")
    @GetMapping("/list")
    public ApiResult<List<BizDeviceInfo>> list(BizDeviceInfo bizDeviceInfo)
    {
        startPage();
        List<BizDeviceInfo> list = bizDeviceInfoService.selectBizDeviceInfoList(bizDeviceInfo);
        return ApiResult.page(list, new PageInfo(list).getTotal());
    }

    /**
     * 导出设备信息列表
     */
    @ApiOperation("导出设备信息列表")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizDeviceInfo bizDeviceInfo)
    {
        List<BizDeviceInfo> list = bizDeviceInfoService.selectBizDeviceInfoList(bizDeviceInfo);
        ExcelUtil<BizDeviceInfo> util = new ExcelUtil<BizDeviceInfo>(BizDeviceInfo.class);
        util.exportExcel(response, list, "设备信息数据");
    }

    /**
     * 获取设备信息详细信息
     */
    @ApiOperation("获取设备信息详细信息")
    @ApiImplicitParam(name = "deviceId", value = "设备信息ID", dataType = "String", dataTypeClass = String.class, required = true)
    @GetMapping(value = "/getInfo/{deviceId}")
    public ApiResult<BizDeviceInfo> getInfo(@PathVariable("deviceId") String deviceId)
    {
        return ApiResult.ok(bizDeviceInfoService.selectBizDeviceInfoByDeviceId(deviceId));
    }

    /**
     * 新增设备信息
     */
    @ApiOperation("新增设备信息")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public ApiResult<Integer> add(@RequestBody BizDeviceInfo bizDeviceInfo)
    {
        return ApiResult.toR(bizDeviceInfoService.insertBizDeviceInfo(bizDeviceInfo));
    }

    /**
     * 修改设备信息
     */
    @ApiOperation("修改设备信息")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public ApiResult<Integer> edit(@RequestBody BizDeviceInfo bizDeviceInfo)
    {
        return ApiResult.toR(bizDeviceInfoService.updateBizDeviceInfo(bizDeviceInfo));
    }

    /**
     * 删除设备信息
     */
    @ApiOperation("删除设备信息")
    @ApiImplicitParam(name = "deviceIds", value = "设备信息ID数组", dataType = "String[]", dataTypeClass = String[].class, required = true)
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{deviceIds}")
    public ApiResult<Integer> remove(@PathVariable("deviceIds") String[] deviceIds)
    {
        return ApiResult.toR(bizDeviceInfoService.deleteBizDeviceInfoByDeviceIds(deviceIds));
    }

    /**
     * @param deviceInfo
     * @return {@link ApiResult}<{@link Integer}>
     */
    @ApiOperation("修改设备状态")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public ApiResult<Integer> changeStatus(@RequestBody BizDeviceInfo deviceInfo) {
        return ApiResult.toR(bizDeviceInfoService.changeStatus(deviceInfo));
    }
}
